<script setup>
import { onMounted, ref, computed } from "vue";
import { useRouter } from "vue-router";
import { isAdmin, logout } from "../services/auth";
import { useUserStore } from "../stores/user";

const router = useRouter();
const userStore = useUserStore();
const showDropdown = ref(false);

// 使用计算属性从store获取用户信息
const userInfo = computed(() => userStore.userInfo);

onMounted(() => {
  // 检查是否是管理员
  if (!isAdmin()) {
    router.push("/login");
    return;
  }

  userStore.loadUserInfo();
});

const handleLogout = () => {
  logout();
  userStore.updateUserInfo(null);
  router.push("/login");
};
</script>

<template>
  <div class="min-h-screen bg-gray-100">
    <!-- 主内容区 -->
    <main class="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
      <router-view />
    </main>
  </div>
</template>